﻿using System;
using System.Collections.Generic;
using Sharp3D.Math.Core;
using ReAnimation.Helpers.Common;
using System.Linq;


namespace ReAnimation.Domain
{
    [Serializable]
    public class Molecule
    {
        private IList<Atom> _atoms;
        private IList<Link> _links;

        public String Name { get; set; }

        public virtual ZMatrix MoleculeZMatrix { get; set; }

        public virtual IEnumerable<Atom> Atoms 
        {
            get
            {
                return _atoms;
            }
            set
            {
                _atoms = new List<Atom>(value);
            }
        }

        public virtual IEnumerable<Link> Links
        {
            get
            {
                return _links;
            }
            set
            {
                _links = new List<Link>(value);
            }
        }

        public virtual Matrix4F TransformMatrix { get; set; }

        public Molecule()
        {
            Atoms = new List<Atom>();
            Links = new List<Link>();
            MoleculeZMatrix = new ZMatrix();
            TransformMatrix = Matrix4F.Identity;
        }

        public override string ToString()
        {
            return Name;
        }

        public virtual void AddAtom(Atom atom)
        {
            _atoms.Add(atom);
        }

        public virtual void RemoveAtom(Atom atom)
        {
            _atoms.Remove(atom);
        }

        public virtual void AddLink(Link link)
        {
            _links.Add(link);
        }

        public virtual void RemoveLink(Link link)
        {
            _links.Remove(link);
        }

        public virtual void SetAtomsAndLinks(IEnumerable<Atom> atoms, IEnumerable<Link> links)
        {
            _atoms = new List<Atom>(atoms);
            _links = new List<Link>(links);
        }
    }
}